# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libffi
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.1
pkgrel=2
pkgdesc="A portable, high level programming interface to various calling conventions (mingw-w64)"
arch=('any')
groups=("${MINGW_PACKAGE_PREFIX}")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
license=('MIT')
url="http://sourceware.org/libffi"
source=("ftp://sourceware.org/pub/libffi/${_realname}-${pkgver}.tar.gz"
        libffi-3.1-missing-gnu-stack.patch
        libffi-3.1-typo.patch
        toolexeclibdir-subst.patch)
md5sums=('f5898b29bbfd70502831a212d9249d10'
         '19f34af77b7b04cfc9b5eb47c2ec268c'
         '2a5a48fbe64966989e7806dae17c8f1a'
         'ad0e622c36e16e2152bad7b900600b7d')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/libffi-3.1-missing-gnu-stack.patch
  patch -p1 -i ${srcdir}/libffi-3.1-typo.patch
  patch -p0 -i ${srcdir}/toolexeclibdir-subst.patch
  
  autoreconf -fi
}

build() {
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
